﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TomVanGaever.SharePoint.VS2010.BCSForm
{
    public class BCSArguments
    {
        private string _location;

        public string Location
        {
            get { return _location; }
        }

        public BCSArguments()
        {
            _location = string.Empty;
        }

        public BCSArguments(string[] args)
            : this()
        {
            if (args.Count() == 0) throw new ArgumentException("-path argument is required");

            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];
                if (arg[0] != '-' && arg[0] != '/')
                    throw new ArgumentException(String.Concat("Invalid argument '", arg, "'"));
                switch (arg.TrimStart('-', '/'))
                {
                    case "path":
                        _location = TextArgument(args, ref i);
                        break;

                }
            }
        }

        private string TextArgument(string[] args, ref int i)
        {
            if (args.Length < i + 2) throw new ArgumentException();
            string value = args[++i];
            if (value[0] == '-' || value[0] == '/') throw new ArgumentException();
            return value;
        }
    }
}
